class MainController < ApplicationController
  before_filter :login_required, :only=>['welcome', 'hidden']
  def index
   render :action => 'login'
  end

  def login
    if request.post?
      if session[:usuario] = Usuario.authenticate(params[:usuario][:matricula], params[:usuario][:senha])
        flash[:aviso]  = "Logado com sucesso"
        flash[:aviso]  = "Logado com sucesso"
        redirect_to_stored
      else
        flash[:aviso] = "Falha ao logar"
      end
      @date = Date.today
    end
  end
  
  def logout
    session[:usuario] = nil
    flash[:aviso] = 'Sessão fechada'
    redirect_to :action => 'login'
  end
  
#  def do_login
#    username = params[:matricula]
#    password = params[:senha]
#    if matricula.nil? || senha.nil? 
#      redirect_to :action => "login"
#      flash[:notice] = 'Usuário ou senha incorretos'   
#    else   
#      session["matricula"] = matricula      
#      redirect_to :controller => "secure", :action => "index"
#    end
#  end
  
  def welcome
  end
  def hidden
  end

end
